package com.uchengwang.ui.cm_ui.me.ui;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.uchengwang.R;
import com.uchengwang.functions.http.config.BaseConfig;
import com.uchengwang.ui.base_ui.ui.BaseWithTitleActivity;
import com.uchengwang.ui.cm_ui.me.adapter.RefuseAdapter;
import com.uchengwang.ui.cm_ui.me.bean.RefuseBean;
import com.uchengwang.ui.cm_ui.ucity.cityBean.UcityInfoBean;
import com.uchengwang.ui.cm_ui.umsg.bean.WantChatBean;
import com.uchengwang.ui.utils.UCommonUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by U城网 on 2017/11/1.
 * Uni审核信息拒绝原因
 */

public class RefuseReasonActivity extends BaseWithTitleActivity{
    private RecyclerView refuse_rv;
    private Button refuse_bt;
    private RefuseAdapter adapter;

    private UcityInfoBean bean;
    private WantChatBean chatBean;
    private EditText refuse_edit;
    private int type;//0U城信息  1享聊信息
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_refuse_reason);
        setTitle("拒绝原因");
        type = getIntent().getIntExtra(BaseConfig.TYPE, 0);
        switch (type){
            case 0:
                bean = (UcityInfoBean) getIntent().getSerializableExtra(BaseConfig.BEAN);
                break;
            case 1://享聊
                chatBean = (WantChatBean) getIntent().getSerializableExtra(BaseConfig.BEAN);
                break;
        }

        initView();

    }

    private void initView() {
        refuse_rv = (RecyclerView) findViewById(R.id.refuse_rv);
        refuse_bt = (Button) findViewById(R.id.refuse_bt);
        refuse_edit = (EditText) findViewById(R.id.refuse_edit);

        refuse_bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                List<RefuseBean> listData = adapter.getData();

                String reason = "";
                for (RefuseBean bean : listData){
                    if (bean.isCheck()){
                        reason = bean.getTitle();
                        break;
                    }
                }

                String edit = refuse_edit.getText().toString();
                if (!TextUtils.isEmpty(edit)){
                    reason = edit;
                }

                if (TextUtils.isEmpty(reason)){
                    UCommonUtil.getUtil().showToast(RefuseReasonActivity.this, "请选择原因");
                    return;
                }

                //提交拒绝
                switch (type){
                    case 0://U城信息
//                        HttpAcManager.getManager().examineData(RefuseReasonActivity.this, bean.getId(), reason, true, new OnResultListener() {
//                            @Override
//                            public void onResult(int stutas, String msg, int total, String data) {
//                                if (stutas ==0){
//
//                                    bean.setExamine(2);
//                                    EventBus.getDefault().post(bean);
//
//                                    Intent intent = new Intent();
//                                    intent.putExtra(BaseConfig.IS_EXAMINE, 2);
//                                    setResult(1, intent);
//                                    RefuseReasonActivity.this.finish();
//                                }else {
//                                    UCommonUtil.getUtil().showToast(RefuseReasonActivity.this, msg);
//                                }
//                            }
//                        });
                        break;
                    case 1://享聊
//                        ChatHttpManager.getManager().wantExamine(RefuseReasonActivity.this, 1, chatBean.getUid(), false, reason, new OnResultListener() {
//                            @Override
//                            public void onResult(int stutas, String msg, int total, String data) {
//                                if (stutas ==0){
//
//                                    chatBean.setIsExamine(-1);
//                                    EventBus.getDefault().post(chatBean);
//
//                                    Intent intent = new Intent();
//                                    intent.putExtra(BaseConfig.IS_EXAMINE, -1);
//                                    setResult(1, intent);
//                                    RefuseReasonActivity.this.finish();
//                                }else {
//                                    UCommonUtil.getUtil().showToast(RefuseReasonActivity.this, msg);
//                                }
//                            }
//                        });

                        break;
                }



            }
        });

        initData();

    }

    private void initData(){
        List<RefuseBean> list = new ArrayList<>();
        switch (type){
            case 0://U城信息
                list.add(new RefuseBean("违规", true));
                list.add(new RefuseBean("重复发布", false));
                list.add(new RefuseBean("信息不完整", false));
                list.add(new RefuseBean("图文质量差", false));
                list.add(new RefuseBean("其他", false));
                break;
            case 1://享聊信息
                list.add(new RefuseBean("非真实头像", true));
                list.add(new RefuseBean("涉嫌违规", false));
                break;
        }

        adapter = new RefuseAdapter(this, list);
        refuse_rv.setLayoutManager(new LinearLayoutManager(this));
        refuse_rv.setAdapter(adapter);
    }
}